import { Injectable } from '@nestjs/common';
import { ResponseUtil } from 'src/common/utils/response.util';
@Injectable()
export class NetworkService {
  private subnetList = Array.from({ length: 100 }, (_, i) => (
    {
      id: i,
      createdBy: '',
      createdTime: 1745485427000,
      updatedBy: '',
      updatedTime: 1745819266000,
      netConfId: i,
      ip: `192.168.${i}.0/24`,
      ipv6: `2001:db8:1234:5678::${i}/64`,
      type: 0,
      subnetCode: 7,
    }));
  private ipvStatusNumber:number = 1

  //根据宿主机ip配置子网网段
  async configSubnet(body) {
    return ResponseUtil.success('success', '配置子网网段成功');
  }

  // 根据下发数量查询可用子网ipv4和ipv6
  async showSubnet(body: any) {
    const { number } = body;
    const data = this.subnetList.slice(0, number);
    return ResponseUtil.success(data, '查询可用子网ipv4和ipv6成功');
  }

  // 批量验证修改后的ipv4地址和ipv6地址是否可用
  async batchVerify(body:any){
    const data = []
    this.subnetList.forEach(item => {
      const result = body.find((resultItem) => resultItem.netConfId === item.netConfId);
       console.log(result,"result");
      if (result) {
        result.ipv4Status = this.ipvStatusNumber%2==0?0:1;//0到1随机数
        result.ipv6Status = this.ipvStatusNumber%2==0?0:1;
        result.netConfId = item.netConfId;
        data.push(result);
      }
    });
    this.ipvStatusNumber++
    return ResponseUtil.success(data, '查询可用子网ipv4和ipv6成功');
  }

}


